//
//  UIButton+Extension.swift
//  weibo
//
//  Created by Fosen on 15/12/2.
//  Copyright © 2015年 fosen. All rights reserved.
//

import UIKit


//给UIButton扩展构造方法

//扩展构造方法

//分类中不能够添加只读属性和方法

extension UIButton{


    convenience init(title :String,backImage :String?, color :UIColor,fontSize :CGFloat = 15,imageName: String?,isNeedHighlighted: Bool = false){

        self.init()
        //设置title
        setTitle(title, forState: .Normal)
        setTitleColor(color, forState: .Normal)
        titleLabel?.font = UIFont.systemFontOfSize(15)
    
        if backImage != nil {
            setBackgroundImage(UIImage(named: backImage!), forState: .Normal)
            if isNeedHighlighted {
                setBackgroundImage(UIImage(named: backImage! + "_highlighted"), forState: .Highlighted)
            
            }
        }
        if imageName != nil {
        
            setImage(UIImage(named: imageName!), forState: .Normal)
        }
        sizeToFit()
    }

    
//
    convenience init(backImage :String,imageName: String){
        
        self.init()
        //设置title

        setBackgroundImage(UIImage(named: backImage), forState: .Normal)
        setBackgroundImage(UIImage(named: backImage + "_highlighted"), forState: .Highlighted)
        setImage(UIImage(named: imageName), forState: .Normal)
        setImage(UIImage(named: imageName + "_highlighted"), forState: .Normal)

        sizeToFit()
    }

}
